package jp.co.hcs.attendancemanagement.dialog.logic;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import jp.co.hcs.attendancemanagement.data.dao.WorkDAO;
import jp.co.hcs.attendancemanagement.data.entity.Work;
import jp.co.hcs.attendancemanagement.dialog.logic.dto.WorkDTO;
import jp.co.hcs.attendancemanagement.logic.LogicBase;

/**
 * The Class WorkSearchLogic.
 */
public class WorkSearchLogic extends LogicBase {

  /** The work dao. */
  private WorkDAO workDao;

  /**
   * Search work.
   * 
   * @param divisionId the division id
   * @param departmentId the department id
   * @return the list
   */
  public List<WorkDTO> searchWork(String divisionId, String departmentId) {
    List<WorkDTO> workList = new ArrayList<WorkDTO>();
    try {
      List<Work> result =
          getWorkDao().retrieveWorkListByDivisionAndDepartment(divisionId, departmentId);
      WorkDTO dto;
      for (Work work : result) {
        dto = new WorkDTO();
        dto.setWorkId(work.getWorkId());
        dto.setWorkName(work.getWorkName());
        workList.add(dto);
      }
    } catch (SQLException e) {
    }
    return workList;
  }

  /**
   * Gets the work dao.
   * 
   * @return the work dao
   */
  public WorkDAO getWorkDao() {
    if (workDao == null) {
      workDao = daoFactory.getWorkDAO();
    }

    return workDao;
  }

  /**
   * Sets the work dao.
   * 
   * @param workDao the new work dao
   */
  public void setWorkDao(WorkDAO workDao) {
    this.workDao = workDao;
  }

}
